#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[])
{
	FILE *random;
	char rand_data;
	int key_length, num_bytes;
	int i;
	
	if(argc != 2)
	{
		printf("Usage: ./gen_key <length>\n");
		exit(1);
	}
	
	key_length = atoi(argv[1]);
	num_bytes = key_length >> 3;
	random = fopen("/dev/random","r");
	
	if(random == NULL)
	{
		printf("Could not open /dev/random.\n");
		exit(1);
	}
	
	for(i = 0; i < num_bytes; i++)
	{
		fread((void*)(&rand_data),1,1,random);
		printf("%.2hhx",rand_data);
	}
	printf("\n");
	fclose(random);
	return 0;
}
